/**
 * 
 */
package org.tiger.netty.client.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

/**
 * @author liuwenlai
 *
 */
public class TigerClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
	private static Logger logger = LoggerFactory.getLogger(TigerClientHandler.class);

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		ctx.writeAndFlush(Unpooled.copiedBuffer("netty rocks!", CharsetUtil.UTF_8));
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		logger.error("client receive error: " + cause);
		ctx.close();
	}

	@Override
	protected void channelRead0(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramI) throws Exception {
		logger.info("client received :" + paramI.toString(CharsetUtil.UTF_8));
	}

}
